/*
	Copyright (C) 2010 Salil Bhagurkar

	This file is part of k3

	k3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	k3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with k3.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>

/**
 * Append works as generic when reading, but appends to itself when written to.
 */

static int vmdrvstringappend_write(struct fs *referrer, struct fs *this, struct buffer *buf, u32 offset, u32 count)
{
	//Simply call the generic function and set offset at the end
	return fs_system_generic_write(referrer, this, buf, this->buf.len, count);
}
/*
firstName <- input
lastName  <- input

*/
static void vmdrvstringappend_init(struct fs *string_fs)
{
	struct fs *append_fs;
	append_fs = fs_create(FSFLAGS_VMDRV, "append");
	append_fs->system = fs_create_system(0, fs_system_generic_read, vmdrvstringappend_write, dummy, append_fs);
	fs_link(string_fs, append_fs);
}

int vmdrvstring_init()
{
	dprint(D_PROG, "string", "Initialize vmdrv");
	struct fs *string_fs;
	string_fs = fs_create(FSFLAGS_VMDRV, "string");
	fs_link(fsparse_get("/vmdrv"), string_fs);
	vmdrvstringappend_init(string_fs);
	return 0;
}
